package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BusInsomniaAlert;
import com.ruoyi.system.service.IBusInsomniaAlertService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 失眠预警Controller
 * 
 * @author wuxiao
 * @date 2025-09-29
 */
@Controller
@RequestMapping("/system/alert")
public class BusInsomniaAlertController extends BaseController
{
    private String prefix = "system/alert";

    @Autowired
    private IBusInsomniaAlertService busInsomniaAlertService;

    @RequiresPermissions("system:alert:view")
    @GetMapping()
    public String alert()
    {
        return prefix + "/alert";
    }

    /**
     * 查询失眠预警列表
     */
    @RequiresPermissions("system:alert:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BusInsomniaAlert busInsomniaAlert)
    {
        startPage();
        List<BusInsomniaAlert> list = busInsomniaAlertService.selectBusInsomniaAlertList(busInsomniaAlert);
        return getDataTable(list);
    }

    /**
     * 导出失眠预警列表
     */
    @RequiresPermissions("system:alert:export")
    @Log(title = "失眠预警", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BusInsomniaAlert busInsomniaAlert)
    {
        List<BusInsomniaAlert> list = busInsomniaAlertService.selectBusInsomniaAlertList(busInsomniaAlert);
        ExcelUtil<BusInsomniaAlert> util = new ExcelUtil<BusInsomniaAlert>(BusInsomniaAlert.class);
        return util.exportExcel(list, "失眠预警数据");
    }

    /**
     * 新增失眠预警
     */
    @RequiresPermissions("system:alert:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存失眠预警
     */
    @RequiresPermissions("system:alert:add")
    @Log(title = "失眠预警", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BusInsomniaAlert busInsomniaAlert)
    {
        return toAjax(busInsomniaAlertService.insertBusInsomniaAlert(busInsomniaAlert));
    }

    /**
     * 修改失眠预警
     */
    @RequiresPermissions("system:alert:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        BusInsomniaAlert busInsomniaAlert = busInsomniaAlertService.selectBusInsomniaAlertById(id);
        mmap.put("busInsomniaAlert", busInsomniaAlert);
        return prefix + "/edit";
    }

    /**
     * 修改保存失眠预警
     */
    @RequiresPermissions("system:alert:edit")
    @Log(title = "失眠预警", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BusInsomniaAlert busInsomniaAlert)
    {
        return toAjax(busInsomniaAlertService.updateBusInsomniaAlert(busInsomniaAlert));
    }

    /**
     * 删除失眠预警
     */
    @RequiresPermissions("system:alert:remove")
    @Log(title = "失眠预警", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(busInsomniaAlertService.deleteBusInsomniaAlertByIds(ids));
    }
}
